﻿<%@ Control Language="VB" AutoEventWireup="false" CodeFile="Uc_main_system_fv.ascx.vb"
    Inherits="Apps_Shares_Uc_menu_fvl" %>

<script type="text/javascript">
//<!--    Begin
    /* This script and many more are available free online at
    The JavaScript Source!! http://javascript.internet.com
    Created by: Abraham Joffe :: http://www.abrahamjoffe.com.au/ */

    /***** CUSTOMIZE THESE VARIABLES *****/

    // width to resize large images to
    var maxWidth = 100;
    // height to resize large images to
    var maxHeight = 100;
    // valid file types
    var fileTypes = ["bmp", "gif", "png", "jpg", "jpeg"];
    // the id of the preview image tag
    var outImage = "ctl00_cphBody_Uc_main_system_fv1_fv_imgSystem";
    // what to display when the image is not valid
    var defaultPic = "spacer.gif";

    /***** DO NOT EDIT BELOW *****/

    function preview(what) {
        var source = what.value;
        var ext = source.substring(source.lastIndexOf(".") + 1, source.length).toLowerCase();
        for (var i = 0; i < fileTypes.length; i++) if (fileTypes[i] == ext) break;
        globalPic = new Image();
        if (i < fileTypes.length) 
        {
            $('#ctl00_cphBody_Uc_main_system_fv1_fv_imgSystem').attr('src', source);
        }
        else {
            globalPic.src = defaultPic;
            alert("THAT IS NOT A VALID IMAGE\nPlease load an image with an extention of one of the following:\n\n" + fileTypes.join(", "));
        }
        
    }

// End -->
</script>

<asp:FormView ID="fv" runat="server" RenderOuterTable="False" DefaultMode="Edit"
    DataSourceID="fvSrc" EnableModelValidation="True" Width="100%">
    <InsertItemTemplate>
        <table cellspacing="2" cellpadding="2" bordercolor="#cccccc" border="1" align="center"
            width="60%">
            <tbody>
                <tr>
                    <td bgcolor="#999999" align="center" class="th_data" colspan="2">
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อระบบ <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:TextBox ID='txtSystemName' runat='server' CssClass='text_normal' Text='<%# Bind("main_system_name") %>'></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ประเภทของระบบ <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:DropDownList ID='ddlSystemType' runat='server' SelectedValue='<%# Bind("main_system_type") %>'>
                            <asp:ListItem Text='ประเภท' Value='0'></asp:ListItem>
                            <asp:ListItem Text='ข้อมูลหลักของระบบ' Value='1'></asp:ListItem>
                            <asp:ListItem Text='ข้อมูลปฏิบัติงาน' Value='2'></asp:ListItem>
                        </asp:DropDownList>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">รูปภาพ  :</td>
                    <td align="left" class="td_box">
                        <asp:FileUpload ID='fImage' runat='server' />
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        สถานะ <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:RadioButtonList ID='rblStatus' runat='server' RepeatDirection="Horizontal" SelectedValue='<%# Bind("main_system_status") %>'
                            CssClass='text_normal'>
                            <asp:ListItem Text='ใช้งาน' Value='1' Selected='True'></asp:ListItem>
                            <asp:ListItem Text='ไม่ใช้งาน' Value='2'></asp:ListItem>
                        </asp:RadioButtonList>
                    </td>
                </tr>
                <tr>
                    <td bgcolor="#999999" align="center" class="td_data_end" colspan="2">
                        <asp:Button ID='btnSubmit' runat='server' Text='บันทึก' CommandName="Insert" ValidationGroup='g1' />
                        <asp:Button ID='btnMainMenu' Text='<%$ Resources:Resource,BTN_MAINMENU %>' runat='server' PostBackUrl="~/Apps/ViewSystem.aspx?Edit=2" />
                        <div class="hide">
                            <asp:RequiredFieldValidator ID="txtSystemNameRequiredFieldValidator" runat="server"
                                ControlToValidate="txtSystemName" ErrorMessage="กรุณากรอกชือระบบ" SetFocusOnError="True"
                                ValidationGroup="g1"></asp:RequiredFieldValidator>
                            <br />
                            <asp:RequiredFieldValidator ID="ddlSystemTypeRequiredFieldValidator" runat="server"
                                ControlToValidate="ddlSystemType" ErrorMessage="กรุณาเลือกประเภทของระบบ" InitialValue="0"
                                SetFocusOnError="True" ValidationGroup="g1"></asp:RequiredFieldValidator>
                            <br />
                            <asp:RequiredFieldValidator ID="rblStatusRequiredFieldValidator" runat="server" ControlToValidate="rblStatus"
                                ErrorMessage="<%$ Resources:Resource, MSG_REQ_STATUS %>" SetFocusOnError="True"
                                ValidationGroup="g1"></asp:RequiredFieldValidator>
                            <br />
                            <asp:ValidationSummary ID="fvValidationSummary" runat="server" ShowMessageBox="True"
                                ValidationGroup="g1" />
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
    </InsertItemTemplate>
    <EditItemTemplate>
        <table cellspacing="2" cellpadding="2" bordercolor="#cccccc" border="1" align="center"
            width="60%">
            <tbody>
                <tr>
                    <td bgcolor="#999999" align="center" class="th_data" colspan="2">
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อระบบ <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:TextBox ID='txtSystemName' runat='server' CssClass='text_normal' Text='<%# Bind("main_system_name") %>'></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ประเภทของระบบ <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:DropDownList ID='ddlSystemType' runat='server' SelectedValue='<%# Bind("main_system_type") %>'>
                            <asp:ListItem Text='ประเภท' Value='0'></asp:ListItem>
                            <asp:ListItem Text='ข้อมูลหลักของระบบ' Value='1'></asp:ListItem>
                            <asp:ListItem Text='ข้อมูลปฏิบัติงาน' Value='2'></asp:ListItem>
                        </asp:DropDownList>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">รูปภาพ :</td>
                    <td align="left" class="td_box">
                        <asp:FileUpload ID='fImage' runat='server' onchange="preview(this)" />
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        &nbsp;
                    </td>
                    <td align="left" class="td_box">
                        <asp:Image ID="imgSystem" runat="server" Height="128px" ImageUrl='<%# Bind("main_system_picture") %>'
                            Width="128px" />
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        สถานะ <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:RadioButtonList ID='rblStatus' runat='server' RepeatDirection="Horizontal" SelectedValue='<%# Bind("main_system_status") %>'
                            CssClass='text_normal'>
                            <asp:ListItem Text='ใช้งาน' Value='1' Selected='True'></asp:ListItem>
                            <asp:ListItem Text='ไม่ใช้งาน' Value='2'></asp:ListItem>
                        </asp:RadioButtonList>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อและวันเวลาที่สร้างข้อมูล :
                    </td>
                    <td align="left" class="td_box">
                        <asp:Literal ID='ltrCreate' runat='server' Text='<%# Eval("Creator") %>'></asp:Literal>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อและวันเวลาที่ปรับปรุงข้อมูล :
                    </td>
                    <td align="left" class="td_box">
                        <asp:Literal ID='ltrUpdate' runat='server' Text='<%# Eval("Editor") %>'></asp:Literal>
                    </td>
                </tr>
                <tr>
                    <td bgcolor="#999999" align="center" class="td_data_end" colspan="2">
                        <asp:Button ID='btnSubmit' runat='server' Text='บันทึก' CommandName="Update" ValidationGroup="g1" />
                        <asp:Button ID='btnCancel' runat='server' Text='ยกเลิก' PostBackUrl="~/Apps/main_system_list.aspx?Edit=true" />
                        <asp:Button ID='btnMainMenu' Text='<%$ Resources:Resource,BTN_MAINMENU %>' runat='server' PostBackUrl="~/Apps/ViewSystem.aspx?Edit=2" />
                        <div class="hide">
                            <asp:RequiredFieldValidator ID="txtSystemNameRequiredFieldValidator" runat="server"
                                ControlToValidate="txtSystemName" ErrorMessage="กรุณากรอกชือระบบ" SetFocusOnError="True"
                                ValidationGroup="g1"></asp:RequiredFieldValidator>
                            <br />
                            <asp:RequiredFieldValidator ID="ddlSystemTypeRequiredFieldValidator" runat="server"
                                ControlToValidate="ddlSystemType" ErrorMessage="กรุณาเลือกประเภทของระบบ" InitialValue="0"
                                SetFocusOnError="True" ValidationGroup="g1"></asp:RequiredFieldValidator>
                            <br />
                            <asp:RequiredFieldValidator ID="rblStatusRequiredFieldValidator" runat="server" ControlToValidate="rblStatus"
                                ErrorMessage="<%$ Resources:Resource, MSG_REQ_STATUS %>" SetFocusOnError="True"
                                ValidationGroup="g1"></asp:RequiredFieldValidator>
                            <br />
                            <asp:ValidationSummary ID="fvValidationSummary" runat="server" ShowMessageBox="True"
                                ValidationGroup="g1" />
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
    </EditItemTemplate>
    <ItemTemplate>
        <table cellspacing="2" cellpadding="2" bordercolor="#cccccc" border="1" align="center"
            width="60%">
            <tbody>
                <tr>
                    <td bgcolor="#999999" align="center" class="th_data" colspan="2">
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อระบบ :
                    </td>
                    <td align="left" class="td_box">
                        &nbsp;
                        <asp:Literal ID='txtSystemName' runat='server' Text='<%# Bind("main_system_name") %>'></asp:Literal>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ประเภทของระบบ :
                    </td>
                    <td align="left" class="td_box">
                        &nbsp;
                        <asp:Literal ID='ddlSystemType' runat='server' Text='<%# CodeMatrix.Business.GenericData.GetSystemTypeLabel(Eval("main_system_type"))  %>'></asp:Literal>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        &nbsp; รูปภาพ :
                    </td>
                    <td align="left" class="td_box">
                        &nbsp;
                        <asp:Image ID="imgSystem" runat="server" Height="128px" ImageUrl='<%# Eval("main_system_picture") %>'
                            Width="128px" />
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        สถานะ :
                    </td>
                    <td align="left" class="td_box">
                        &nbsp;
                        <asp:Literal ID='ltrLabel' runat='server' Text='<%# CodeMatrix.Business.GenericData.GetStatusLabel(Eval("main_system_status")) %>'></asp:Literal>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อและวันเวลาที่สร้างข้อมูล :
                    </td>
                    <td align="left" class="td_box">
                        &nbsp;
                        <asp:Literal ID='ltrCreate' runat='server' Text='<%# Eval("Creator") %>'></asp:Literal>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อและวันเวลาที่ปรับปรุงข้อมูล :
                    </td>
                    <td align="left" class="td_box">
                        &nbsp;
                        <asp:Literal ID='ltrUpdate' runat='server' Text='<%# Eval("Editor") %>'></asp:Literal>
                    </td>
                </tr>
                <tr>
                    <td bgcolor="#999999" align="center" class="td_data_end" colspan="2">
                        <asp:Button ID='btnSubmit' runat='server' Text='ย้อนกลับ' PostBackUrl="~/Apps/main_system_list.aspx" />
                        <asp:Button ID='btnMainMenu' Text='<%$ Resources:Resource,BTN_MAINMENU %>' runat='server' PostBackUrl="~/Apps/ViewSystem.aspx?Edit=2" />
                    </td>
                </tr>
            </tbody>
        </table>
    </ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="fvSrc" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
    InsertCommand="INSERT INTO [stp_main_system]
           ([main_system_name]
           ,[main_system_type]
           ,[main_system_picture]
           ,[main_system_status]
           ,[staff_code_create]
           ,[create_datetime]
           ,[staff_code_update]
           ,[update_datetime])
     VALUES
           (@main_system_name
           ,@main_system_type
           ,@main_system_picture
           ,@main_system_status
           ,@staff_code_create
           ,getdate()
           ,@staff_code_update
           ,getdate())"   
     SelectCommand="
        select  
            main_system_picture =
                case 
	            when main_system_picture is null  then '~/picture/Folder.png'
	            else '~/Images/'+main_system_picture
	            end,
	        * ,
            Creator = dbo.UFN_GetAuditor(staff_code_create,create_datetime) ,
            Editor = dbo.UFN_GetAuditor(staff_code_update,update_datetime) ,
            [Status] = 
                case main_system_status when 1 then 'ใช้งาน' 
                when 2 then 'ไม่ใช้งาน'
                end
        from stp_main_system
        where main_system_code = @main_system_code" 
    UpdateCommand="UPDATE [stp_main_system]
        SET [main_system_name] = @main_system_name
              ,[main_system_type] = @main_system_type
              ,[main_system_picture] = isnull(@main_system_picture,[main_system_picture])
              ,[main_system_status] = @main_system_status
              ,[staff_code_update] = @staff_code_update
              ,[update_datetime] = getdate()
        WHERE main_system_code = @main_system_code;">
    <InsertParameters>
        <asp:Parameter Name="main_system_name" />
        <asp:Parameter Name="main_system_type" />
        <asp:Parameter Name="main_system_picture" />
        <asp:Parameter Name="main_system_status" />
        <asp:SessionParameter Name="staff_code_create" SessionField="staff_code" />
        <asp:SessionParameter Name="staff_code_update" SessionField="staff_code" />
    </InsertParameters>
    <SelectParameters>
        <asp:QueryStringParameter Name="main_system_code" QueryStringField="Edit" />
    </SelectParameters>
    <UpdateParameters>
        <asp:Parameter Name="main_system_name" />
        <asp:Parameter Name="main_system_type" />
        <asp:Parameter Name="main_system_picture" />
        <asp:Parameter Name="main_system_status" />
        <asp:SessionParameter Name="staff_code_update" SessionField="staff_code" />
        <asp:QueryStringParameter Name="main_system_code" QueryStringField="Edit" />
    </UpdateParameters>
</asp:SqlDataSource>

<script type="text/javascript">

</script>

